package cn.iocoder.yudao.module.api.pay.order.eums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  支付类型
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2024/12/16
 */
@Getter
@AllArgsConstructor
public enum UnifiedPayTypeEnum {

    UNKNOWN("undefined", "未知"),

    WECHAT("wechat", "微信支付"), //默认使用的是APIv3

    MOCK("mock", "模拟"),
    WALLET("wallet", "余额"),
    CASH("cash", "现金"),
    FREE("free", "免费"),
    ;

    @EnumValue
    private final String code;
    private final String name;

    public static UnifiedPayTypeEnum codeOf(String code) {
        return Stream.of(values())
                .filter(p -> Objects.equals(p.code, code))
                .findAny()
                .orElse(UNKNOWN);
    }

    public static UnifiedPayTypeEnum channelCodeOf(String channelCode) {
        UnifiedPayChannelEnum payChannelEnum = UnifiedPayChannelEnum.getByCode(channelCode);
        return switch (payChannelEnum) {
            case WX_LITE, MALLBOOK_WX_LITE -> WECHAT;
            case WALLET -> WALLET;
            case MOCK -> MOCK;
            case CASH -> CASH;
            case FREE -> FREE;
            default -> UNKNOWN;
        };
    }

}
